package chapter6.eg3;

import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerAdapter;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.DefaultChannelPipeline;
import io.netty.channel.socket.nio.NioServerSocketChannel;
import org.junit.Test;

public class ChannelPipelineExample {

  @Test
  public void testChangePipeline() {
    Channel channel = new NioServerSocketChannel();
    ChannelPipeline pipeline = new DefaultChannelPipeline(channel) {};
    FirstHandler firstHandler = new FirstHandler();
    pipeline.addLast("handler1", firstHandler);
    pipeline.addFirst("handler2", new SecondHandler());
    pipeline.addLast("handler3", new ThirdHandler());

    pipeline.remove("handler3");
    pipeline.remove(firstHandler);
    pipeline.replace("handler2", "handler4", new ForthHandler());
  }

  @Test
  public void testChannel() {

  }

  private static final class FirstHandler extends ChannelHandlerAdapter {}
  private static final class SecondHandler extends ChannelHandlerAdapter {}
  private static final class ThirdHandler extends ChannelHandlerAdapter {}
  private static final class ForthHandler extends ChannelHandlerAdapter {}
}
